// pages/logistics/logistics.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    hasLogistics:true,
    hasProblem:true
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var  people= options.id.split("|$|")[0]
    var num= options.id.split("|$|")[1]
    logistic(this, people, num)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return {
      title: '成都品牌服饰批发零售定制',
      path: '/pages/homepage/homepage?id=' + wx.getStorageSync("userid"),
    }
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  }
})

function logistic(that,people,num){//查看物流
  console.log(people);
  console.log(num);
  wx.request({
    url: app.globalData.allUrl + "/logisticsAction/selectLogistics",
    data:{
      expCode: people,
      expNo: num,
    },
    method:'GET',
    success:function(res){
      //console.log(res.data)
      if (res.data.State==0){
        that.setData({
          hasLogistics:false
        })
      } else if (res.data.State == 3 || res.data.State == 2){
        var allOrder = res.data.Traces;
        var next=[];
        var k = allOrder.length
        var first = allOrder[k-1]
       // console.log(allOrder[k - 1])
        for (var i = allOrder.length-2;i>-1;i--){
          next.push(allOrder[i])
        }
        //console.log(next)
        that.setData({
          orders: res.data,
          next: next,
          first: first
        })
      } else if (res.data.State == 4){
        that.setData({
          hasProblem: false
        })
      }
    }
  })
}